package core.util;

import io.netty.channel.nio.NioEventLoopGroup;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Gong.Yang
 */
@Slf4j
public class ConcurrentUtil {
    public static void commit(List<Runnable> runnableList) {
        commit(runnableList, 8, 1);
    }

    @SneakyThrows
    public static void commit(List<Runnable> runnableList, int core, int timeOutHours) {
        NioEventLoopGroup eventExecutors = new NioEventLoopGroup(core);

        for (Runnable runnable : runnableList) {
            eventExecutors.execute(runnable);
        }


        eventExecutors.shutdownGracefully().sync();

    }
}
